using MicroMsg.Scene;
using MicroMsg.UI.Util;
using System;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace MicroMsg.UI.UserContrl
{
	public class ComWebLinkProc : BaseInlineProcess
	{
		private const string PATTERN_STRINGS = "(?is)(http|ftp)://(\\w+[\\./]?)*(\\.(html|htm|aspx|asp|php))?[\\w\\?\\-\\=&%]*";
		protected override int GetProbablyStartPos(string text, int startIndex)
		{
			if (string.IsNullOrEmpty(text))
			{
				return -1;
			}
			if (text.get_Length() <= startIndex)
			{
				return -1;
			}
			string text2 = text.Substring(startIndex, text.get_Length() - startIndex);
			Match match = Regex.Match(text2, "(?is)(http|ftp)://(\\w+[\\./]?)*(\\.(html|htm|aspx|asp|php))?[\\w\\?\\-\\=&%]*");
			if (match.get_Success())
			{
				return match.get_Index() + startIndex;
			}
			return -1;
		}
		protected override Inline GetCurrentElement(string text, int startIndex, ref int elementLen, ref string elementStr)
		{
			if (startIndex < 0)
			{
				return null;
			}
			if (text.get_Length() <= startIndex)
			{
				return null;
			}
			string text2 = text.Substring(startIndex, text.get_Length() - startIndex);
			Match match = Regex.Match(text2, "(?is)(http|ftp)://(\\w+[\\./]?)*(\\.(html|htm|aspx|asp|php))?[\\w\\?\\-\\=&%]*");
			if (match.get_Success())
			{
				if (match.get_Index() != 0)
				{
					return null;
				}
				if (match.get_Groups() != null)
				{
					elementStr = match.get_Value();
					elementLen = match.get_Value().get_Length();
					InlineUIContainer inlineUIContainer = new InlineUIContainer();
					HyperlinkButton hyperlinkButton = new HyperlinkButton();
					hyperlinkButton.set_FontSize(this.mNFontSize);
					hyperlinkButton.set_Margin(new Thickness(0.0, 0.0, 0.0, -5.0));
					hyperlinkButton.set_Content(base.GetMaxString(match.get_Value(), 20));
					hyperlinkButton.set_Style((Style)Application.get_Current().get_Resources().get_Item("LinkStyle"));
					hyperlinkButton.set_Foreground(this.mBrushLink);
					hyperlinkButton.set_Tag(match.get_Value());
					hyperlinkButton.add_Click(new RoutedEventHandler(this.newUrlButton_Click));
					inlineUIContainer.set_Child(hyperlinkButton);
					return inlineUIContainer;
				}
			}
			elementLen = 0;
			elementStr = null;
			return null;
		}
		private void newUrlButton_Click(object sender, RoutedEventArgs e)
		{
			HyperlinkButton hyperlinkButton = sender as HyperlinkButton;
			if (hyperlinkButton == null)
			{
				return;
			}
			string text = hyperlinkButton.get_Tag() as string;
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			ToolFunction.GotoWebLinkInWebView(text, GetA8KeyScene.MMGETA8KEY_SCENE_TIMELINE);
		}
	}
}
